package com.ky.pro.big.data.mr.mobile.dr;

import com.ky.pro.big.data.mr.common.EnvConsts;
import com.ky.pro.big.data.mr.mobile.dr.dto.MobileDataRateInfo;
import com.ky.pro.big.data.mr.wc.WordCountMapper;
import com.ky.pro.big.data.mr.wc.WordCountReducer;
import com.ky.pro.big.data.mr.wc.WordCountTool;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;

import javax.lang.model.SourceVersion;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;

public class MobileDataRateTool extends Configured implements Tool {



    @Override
    public int run(String[] strings) throws Exception {
        Configuration conf = super.getConf();

        Job job = Job.getInstance(conf, "kyMdrDemo");

        job.setJarByClass(MobileDataRateTool.class);

        job.setInputFormatClass(TextInputFormat.class);
        TextInputFormat.addInputPath(job, new Path(System.getProperty(
                EnvConsts.SYS_PROP_MOBILE_DATA_RATE_INPUT_PATH)));

        job.setMapperClass(MobileDataRateMapper.class);
        job.setMapOutputKeyClass(LongWritable.class);
        job.setMapOutputValueClass(MobileDataRateInfo.class);

        job.setReducerClass(MobileDataRateReducer.class);

        job.setOutputKeyClass(LongWritable.class);
        job.setOutputValueClass(MobileDataRateInfo.class);
        job.setOutputFormatClass(TextOutputFormat.class);
        TextOutputFormat.setOutputPath(job, new Path(System.getProperty(
                EnvConsts.SYS_PROP_MOBILE_DATA_RATE_OUTPUT_PATH)));

        boolean b = job.waitForCompletion(true);
        return b ? 0 : 1;
    }
}
